/**
 * @class 渐进粒子组组件
 * @author DuskyHuang 圣子
 * @description 使用这个组件可以模拟无穷无尽的粒子嵌套。
*/

import { _decorator, Component, Node, Prefab, instantiate, Camera, Vec3 } from 'cc';
import { utils, core } from 'cfw';
import { SceneGraph } from 'const';
import { cosmos } from '../proxies/cosmos-proxy';
const { ccclass, property } = _decorator;

@ccclass('cocosmos.ParticleGradients')
export class ParticleGradients extends Component {

    @property(Prefab) public Particles: Prefab = null;

    protected onLoad(): void {
        this._viewer = utils.findNode(MAIN, COSMOS);
        for (let i = 0; i < 5; i++) {
            instantiate(this.Particles).parent = this.node;
        }
    }

    protected update(): void {
        let pow2 = Math.log2(Math.pow(10, cosmos.pow10));
        this.node.children.forEach((star, idx) => {
            let p = idx - pow2;
            p %= 5;
            const mag = Math.pow(2, p + 1);
            star.setScale(mag, mag, mag);
        });
    }

    private _viewer: Node;
}

const v3a = new Vec3;
const { Cameras: { MAIN }, COSMOS } = SceneGraph;